package com.android.hidephotosplus.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.hidephotosplus.R;
import com.android.hidephotosplus.model.ModelDrawer;

public class DrawerAdapter extends ArrayAdapter<ModelDrawer> {

	private Context context;

	private ArrayList<ModelDrawer> arrDrawers;

	private ViewHolder viewHolder;

	private LayoutInflater inflater;

	public DrawerAdapter(Context context, ArrayList<ModelDrawer> arrDrawers) {
		super(context, R.layout.item_list_drawer, arrDrawers);
		this.context = context;
		this.arrDrawers = arrDrawers;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			view = inflater.inflate(R.layout.item_list_drawer, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.image = (ImageView) view.findViewById(R.id.image);
			viewHolder.text = (TextView) view.findViewById(R.id.text);
			view.setTag(viewHolder);
		} else
			viewHolder = (ViewHolder) view.getTag();

		if (position >= 0 && position < arrDrawers.size()) {
			ModelDrawer item = getItem(position);
			viewHolder.image.setImageResource(item.getResource());
			viewHolder.text.setText(item.getName());
		}
		return view;
	}

	private class ViewHolder {
		ImageView image;
		TextView text;
	}
}
